﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@{
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();

    var operatorInfo = UIUtility.GetCurrentUser();

    var menuNames = ViewData["menuName"];

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
      
}
@using (Html.BeginForm("Search", "RepairOrders", FormMethod.Post, new { @id = "searchForm" }))
{

    <table style="width: 100%">
        <tr>
            <td style="width: 10%; text-align: right; height: 40px;">
                受理日期起：
            </td>
            <td style="width: 20%; text-align: left;">
                @Html.Telerik().DatePicker().Name("FromCreatedDate").HtmlAttributes(new { @style = "Width:170px;" }).OpenOnFocus(true).ShowButton(false)
            </td>
            <td style="width: 10%; text-align: right">
                受理日期止：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DatePicker().Name("ToCreatedDate").HtmlAttributes(new { @style = "Width:170px;" }).OpenOnFocus(true).ShowButton(false)
            </td>
            <td style="width: 10%; text-align: right">
                维修单状态：
            </td>
            <td style="width: 30%; text-align: left">
                @Html.Telerik().DropDownList().Name("Status").HtmlAttributes(new { @style = "Width:230px;" }).BindTo(ddlHelper.GetDataSource(ConfigMgr.tblRepairOrderStatus, true, ViewBag.RepairOrderStatus as string, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).Enable((ViewBag.RepairOrderStatus as string).Equals(UIConstants.AllItems))
            </td>
        </tr>
        <tr>
            <td style="width: 20%; text-align: right; height: 40px;">
                厂商：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("Supplier").BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td style="width: 20%; text-align: right">
                营业厅类别：
            </td>
            <td style="width: 20%; text-align: left">
                @*                @Html.Telerik().DropDownList().Name("AgentType").ClientEvents(events => { events.OnChange("agentTypeOnChange"); }).BindTo(ddlHelper.GetAgentTypes(UIConstants.AllItems, false, AgentNo, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).CascadeTo("Agent")*@
                @Html.Telerik().DropDownList().Name("AgentType").HtmlAttributes(new { @style = "width:160px;" }).BindTo(ddlHelper.GetAgentTypes(UIConstants.AllItems, false, AgentNo, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems))).CascadeTo("Agent")
            </td>
            <td style="width: 20%; text-align: right">
                营业厅：
            </td>
            <td style="width: 20%; text-align: left">
                @*                @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:230px;" }).ClientEvents(events => { events.OnLoad("agentonload"); events.OnChange("agentOnChange"); })*@
                @Html.Telerik().DropDownList().Name("Agent").HtmlAttributes(new { @style = "Width:230px;" }).DataBinding(binding => binding.Ajax().Select("_GetAgent", "RepairOrders", new { AgentNo = AgentNo }))
            </td>
        </tr>
        <tr>
            <td style="width: 20%; text-align: right; height: 40px;">
                操作员：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("Operator").BindTo(ddlHelper.GetOPERATORSByAgentNo(menuNames, UIConstants.AllItems, AgentNo, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td style="width: 20%; text-align: right">
                是否维修：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("ddlConfirmRepaired").BindTo(ddlHelper.GetDataSource(ConfigMgr.tblConfirmRepaired, true, UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems)))
            </td>
            <td style="width: 20%; text-align: right">
                是否有备签：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.Telerik().DropDownList().Name("IsNeedSpareObu").HtmlAttributes(new { @style = "Width:230px;" }).BindTo(ddlHelper.GetDataSource(null, false, UIConstants.AllItems, false, new KeyValuePair<string, string>(UIConstants.AllItems, UIConstants.AllItems), new KeyValuePair<string, string>("是", "是"), new KeyValuePair<string, string>("否", "否")))
            </td>
        </tr>
        <tr>
            <td style="width: 20%; text-align: right; height: 40px;">
                标签号：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.TextBox("ObuNO", "", new { @style = "width:140px;font-size:16px;border-Height:20px" })
            </td>
            <td style="width: 20%; text-align: right">
                车牌号：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.TextBox("txtVehicleNo", "", new { @style = "width:140px;font-size:16px;border-Height:20px" })
            </td>
            <td style="width: 20%; text-align: right">
                维修单号：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.TextBox("RepairOrderNO", "", new { @style = "width:220px;font-size:16px;border-Height:20px" })
            </td>
        </tr>
        <tr>
            <td style="width: 20%; text-align: right; height: 40px;">
                手机号：
            </td>
            <td style="width: 20%; text-align: left">
                @Html.TextBox("txtMobileNo", "", new { @style = "width:140px;font-size:16px;" })
            </td>
            <td style="width: 20%; text-align: right; height: 40px;">
                工号：
            </td>
            <td colspan="2" style="width: 20%; text-align: left">
                @Html.TextBox("txtOperator", "", new { @style = "width:50px;height:15px", @MaxLength = 6 })
                (六位工号)
            </td>
            <td style="width: 20%; text-align: center">
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                @Html.Hidden("agentNO", AgentNo, new { @id = "agentNO" })
                @Html.Hidden("menuNames", menuNames, new { @id = "menuNames" })
            </td>
        </tr>
    </table>
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });
        if ("@AgentNo".length != 0) {
            var agentType = $('#AgentType').data('tDropDownList');
            var transferBillStatus = $('#TransferBillStatus').data('tDropDownList');
            agentType.select(1); agentType.disable();
        }
    });


    function agentonload(e) {

        var agent = $('#Agent').data('tDropDownList');
        var agentType = $('#AgentType').data('tDropDownList');
        $.post("/RepairOrders/_GetAgent", { "AgentType": agentType.value(), "AgentNo": "@AgentNo" }, function (data) {
            agent.dataBind(data);
            if (agent != null)
                agent.select(0);
            //            if ("@AgentNo" != "") {
            //                agent.select(1);
            //            }
            //            else {
            //                agent.select(0);
            //            }
        })
    }

    //    function agentOnChange(e) {
    //        debugger;
    //        var agent = $('#Agent').data('tDropDownList');
    //        var operator = $('#Operator').data('tDropDownList');
    //        $.post("/RepairOrders/_GetOperators", { "AgentNo": agent.value() }, function (data) {
    //            operator.dataBind(data);
    //            operator.select(0);
    //        })
    //    }

    function agentTypeOnChange(e) {
        var agent = $('#Agent').data('tDropDownList');
        var agentType = $('#AgentType').data('tDropDownList');
        $.post("/RepairOrders/_GetAgent", { "AgentType": agentType.value(), "AgentNo": "@AgentNo" }, function (data) {
            agent.dataBind(data);
            if (agent != null)
                agent.select(0);
            //            if ("@AgentNo" != "") {
            //                agent.select(1);
            //            }
            //            else {
            //                agent.select(0);
            //            }
        })
    }

    function search() {

        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }

</script>
@{
    ddlHelper.Dispose();    
}
